/***************************************************************
 * Name:      AvmUpdateCreatorMain.h
 * Purpose:   Defines Application Frame
 * Author:    Ke Zhonghua (ke.zhonghua@o-film.com)
 * Created:   2018-07-03
 * Copyright: Ke Zhonghua ()
 * License:
 **************************************************************/

#ifndef AVMUPDATECREATORMAIN_H
#define AVMUPDATECREATORMAIN_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "AvmUpdateCreatorApp.h"
#include "AvmUpdateItemPanel.h"
#include <wx/vscroll.h>
#include <list>
#include <vector>
#include <wx/file.h>
#include <wx/mediactrl.h>
#include "flash_tool.h"

typedef std::vector<AvmUpdateItemPanel*> UpdateItemsList;
typedef std::list<SectionHeader> UpdateSectionHeaders;

class AvmUpdateCreatorFrame: public wxFrame
{
        static wxString AutoMountCmds[4];
    public:
        AvmUpdateCreatorFrame(wxFrame *frame, const wxString& title);
        ~AvmUpdateCreatorFrame();
    private:
        wxSizerItem* updateitem_sizeritem;
        wxSizer* updateitems_sizer;
        UpdateItemsList update_items;
        wxScrolledWindow* update_items_panel;
        wxTextCtrl* txt_output;
        wxButton* btn_sel_outputdir;
        wxButton* btn_add;
        wxString cur_output_file;
    private:
        void InitUI();
        void FreezeAllUpdateItems(bool freeze = true);
        uint32_t CheckIfMountNeeded();
        bool InsertMountCommand(uint32_t mount_need);
        bool AppendNewUpdateItem(AvmUpdateItemPanel* panel);
        void DealOutputDirChange();
        bool LoadOutputFile(const wxString& file);
        bool RemoveItem(AvmUpdateItemPanel* panel);
        void RemoveAllItems();
        bool Load(const wxString& file);
        int InsertUpdateItems(const UpdateSectionHeaders& items);
        void InsertRmCommands();
        wxFileOffset AppendUpdateItemFromFile(wxFile& fi);
        wxFileOffset AppendCmdAndFsfileFromFile(wxFile& fi, SectionHeader& item);
        wxFileOffset AppendFsfileItemFromFile(wxFile& fi, SectionHeader& item);
        wxFileOffset AppendRawitemFromFile(wxFile& fi, SectionHeader& item);
        void MarkAllItemsNew();
        bool DumpMakeCommands(const wxString& dir);//将当前所有项导出为命令保存在目录中
    private:
        enum
        {
            idMenuQuit = 1000,
            idMenuAbout
        };
        void OnOpenUpdatebin(wxCommandEvent& event);
        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);

        void OnBtnAddNewItem(wxCommandEvent& event);
        void OnBtnExecute(wxCommandEvent& event);
        void OnBtnBrowseOutputdir(wxCommandEvent& event);
        void OnDeleteItem(wxCommandEvent& event);
        void OnMenuRemoveAllItems(wxCommandEvent& event); //清除所有
        void OnMenuGenericSettings(wxCommandEvent& event);//常规设置
        void OnMenuDumpCmds(wxCommandEvent& event);//导出命令
        void OnMenuLoadCmds(wxCommandEvent& event);//导入命令
        DECLARE_EVENT_TABLE()
};


#endif // AVMUPDATECREATORMAIN_H
